<?php

namespace app\shop\exception;

use app\shop\library\response\ResponseCode;
use Throwable;

class  FailException extends CustomException
{
    /**
     * 服务器异常
     * @param string         $errorMsg     错误提示
     * @param int|null       $businessCode 业务码
     * @param Throwable|null $previous     捕获到的异常
     * @param array          $errorInfo    额外记录到输出异常的信息
     */
    public function __construct(
        string $errorMsg = ResponseCode::FAIL['msg'],
        int $businessCode = null,
        Throwable $previous = null,
        array $errorInfo = [],
        bool $forceLog = false,
    ) {
        $this->httpStatus   = ResponseCode::FAIL['code'];
        $this->businessCode = $businessCode ?? ResponseCode::FAIL['code'];
        $this->errorMsg     = $errorMsg ?? ResponseCode::FAIL['msg'];
        $this->errorInfo    = $errorInfo;
        $this->forceLog     = $forceLog;

        // 生产环境下记录异常日志
        if ($previous && !app()->isDebug()) {
            $this->forceLog = true;
        }

        parent::__construct($this->errorMsg, $previous, $this->businessCode);
    }
}